////////////////////////////////////////////////
// File: GoodsorderController.java
// Description: Enter summary here after generation.
// Date: 2016-09-23 09:09:34
// Web: http://www.elanzhou.com/
////////////////////////////////////////////////
package com.mvc.controller;
import java.io.IOException;
import java.util.List;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mvc.entity.Goodsorder;
import com.mvc.entity.Meminfo;
import com.mvc.service.DictService;
import com.mvc.service.GoodsorderService;
import com.mvc.service.SyscateService;
import com.pub.MyJson;
import com.pub.Page;
import com.aspose.cells.Cells;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
@Controller
@RequestMapping("MemGoodsorder")
public class MemGoodsorderController {
	protected final transient Log logger = LogFactory.getLog(MemGoodsorderController.class);
	@Autowired
	private GoodsorderService goodsorderService;
	@Autowired
	private DictService dictService;
	@Autowired
	private SyscateService syscateService;
	public MemGoodsorderController() {
	}

	/*列表*/
	@RequestMapping("Index.do")
	public String Index(HttpSession session,ModelMap modelMap, String pageNo, String Ajax) {

		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		Page page = new Page();
		page.setPageNox(pageNo);
		page.setPageSize(15);
		page.setVal(",'Memname':'"+smeminfo.getMemname()+"'");
		String hql = "select a from Goodsorder a where a.Memname='"+smeminfo.getMemname()+"'  order by a.ID desc";
		List list = goodsorderService.getGoodsorderList(hql, page);
		String counthql = "select count(*) from Goodsorder a where a.Memname='"+smeminfo.getMemname()+"'";
		page.setPageCount(goodsorderService.getCount(counthql, page));
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/MemGoodsorder/List";
		} else {
			return "/MemGoodsorder/Index";
		}

	}
	/*添加*/ 
	@RequestMapping("Add.do")
	public String Add(HttpSession session,ModelMap modelMap) 
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		List<Object> fcate=syscateService.getFcate() ;
		modelMap.put("fcate", fcate);
		Date date=new Date();
		DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
		String dqsj=format.format(date);
		modelMap.put("dqsj", dqsj);
		String uuid=java.util.UUID.randomUUID().toString();
		modelMap.put("uuid",uuid); 	
		List gglist=dictService.getAllByKeyname("规格");		
		modelMap.put("gglist",gglist); 	
		List ztlist=dictService.getAllByKeyname("状态");		
		modelMap.put("ztlist",ztlist); 	
		List ddlxlist=dictService.getAllByKeyname("订单类型");		
		modelMap.put("ddlxlist",ddlxlist); 	
		return "/MemGoodsorder/Add";
	}
	/*保存*/
	@RequestMapping("Save.do")
	public void Save(HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, HttpSession session) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		try {
			
			Goodsorder  goodsorder= new Goodsorder();
			boolean tag=true;
		    String Msg="信息保存成功";
             
               if(tag){
                              
               String FieldMemname=(String)request.getParameter("Memname");
             
               if(((FieldMemname!=null)&(!FieldMemname.trim().equals("")))){
            	   FieldMemname=FieldMemname.trim();
                    goodsorder.setMemname(FieldMemname);
                  
        		}else
        		{
        			tag=false;
        			Msg="用户名不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldOrdernum=(String)request.getParameter("Ordernum");
             
               if(((FieldOrdernum!=null)&(!FieldOrdernum.trim().equals("")))){
            	   FieldOrdernum=FieldOrdernum.trim();
                    goodsorder.setOrdernum(FieldOrdernum);
                  
        		}else
        		{
        			tag=false;
        			Msg="订单编号不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldOrdertype=(String)request.getParameter("Ordertype");
             
               if(((FieldOrdertype!=null)&(!FieldOrdertype.trim().equals("")))){
            	   FieldOrdertype=FieldOrdertype.trim();
                    goodsorder.setOrdertype(FieldOrdertype);
                  
        		}else
        		{
        			tag=false;
        			Msg="订单类型不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldOrdertime=(String)request.getParameter("Ordertime");
             
               if(((FieldOrdertime!=null)&(!FieldOrdertime.trim().equals("")))){
            	   FieldOrdertime=FieldOrdertime.trim();
                    goodsorder.setOrdertime(FieldOrdertime);
                  
        		}else
        		{
        			tag=false;
        			Msg="订单日期不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldFname=(String)request.getParameter("Fname");
             
               if(((FieldFname!=null)&(!FieldFname.trim().equals("")))){
            	   FieldFname=FieldFname.trim();
                    goodsorder.setFname(FieldFname);
                  
        		}else
        		{
        			tag=false;
        			Msg="品类不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldCatename=(String)request.getParameter("Catename");
             
               if(((FieldCatename!=null)&(!FieldCatename.trim().equals("")))){
            	   FieldCatename=FieldCatename.trim();
                    goodsorder.setCatename(FieldCatename);
                  
        		}else
        		{
        			tag=false;
        			Msg="品种不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldSpec=(String)request.getParameter("Spec");
             
               if(((FieldSpec!=null)&(!FieldSpec.trim().equals("")))){
            	   FieldSpec=FieldSpec.trim();
                    goodsorder.setSpec(FieldSpec);
                  
        		}else
        		{
        			tag=false;
        			Msg="规格不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldTarget=(String)request.getParameter("Target");
             
               if(((FieldTarget!=null)&(!FieldTarget.trim().equals("")))){
            	   FieldTarget=FieldTarget.trim();
                    goodsorder.setTarget(FieldTarget);
                  
        		}else
        		{
        			tag=false;
        			Msg="对象不能为空！";
        		}
        		}
	         
             
               if(tag){
                              
               String FieldOrderstatus=(String)request.getParameter("Orderstatus");
             
               if(((FieldOrderstatus!=null)&(!FieldOrderstatus.trim().equals("")))){
            	   FieldOrderstatus=FieldOrderstatus.trim();
                    goodsorder.setOrderstatus(FieldOrderstatus);
                  
        		}else
        		{
        			tag=false;
        			Msg="状态不能为空！";
        		}
        		}
	         
            
            MyJson mj=new MyJson();
              if(tag){
                     goodsorderService.Save(goodsorder);	 
        			 mj.setStatusCode(200);
        		 }else
        		 {
        			 mj.setStatusCode(300);
        		 }
             mj.setMessage(Msg);
             mj.setForwardUrl("/MemGoodsorder/Index.do");
             mj.setCallbackType("forward");
             String str=mj.getJson();
			 response.getWriter().print(str);
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
	} 
    
	/*编辑*/
	@RequestMapping("Edit.do")
	public String Edit(HttpSession session,HttpServletRequest request,ModelMap modelMap)
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		List<Object> fcate=syscateService.getFcate() ;
		modelMap.put("fcate", fcate);
		List gglist=dictService.getAllByKeyname("规格");		
		modelMap.put("gglist",gglist); 	
		List ztlist=dictService.getAllByKeyname("状态");		
		modelMap.put("ztlist",ztlist); 	
		List ddlxlist=dictService.getAllByKeyname("订单类型");		
		modelMap.put("ddlxlist",ddlxlist); 	
		String ID=request.getParameter("ID");
		Goodsorder goodsorder=(Goodsorder)goodsorderService.getGoodsorder(ID);
		modelMap.put("goodsorder", goodsorder);
		return "/MemGoodsorder/Edit";
	}
    
    /*编辑保存*/
	@RequestMapping("EditSave.do")
	public void EditSave(HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap,HttpSession session) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		try {
			String Id=(String)request.getParameter("ID");
			Goodsorder  goodsorder=(Goodsorder)goodsorderService.getGoodsorder(Id);
			boolean tag=true;
		    String Msg="信息修改成功";
             
            if(tag){
               
               String FieldMemname=(String)request.getParameter("Memname");
             
               if(((FieldMemname!=null)&(!FieldMemname.trim().equals("")))){
            	   FieldMemname=FieldMemname.trim();
                    goodsorder.setMemname(smeminfo.getMemname());
                  
        		}else
        		{
        			tag=false;
        			Msg="用户名不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldOrdernum=(String)request.getParameter("Ordernum");
             
               if(((FieldOrdernum!=null)&(!FieldOrdernum.trim().equals("")))){
            	   FieldOrdernum=FieldOrdernum.trim();
                    goodsorder.setOrdernum(FieldOrdernum);
                  
        		}else
        		{
        			tag=false;
        			Msg="订单编号不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldOrdertype=(String)request.getParameter("Ordertype");
             
               if(((FieldOrdertype!=null)&(!FieldOrdertype.trim().equals("")))){
            	   FieldOrdertype=FieldOrdertype.trim();
                    goodsorder.setOrdertype(FieldOrdertype);
                  
        		}else
        		{
        			tag=false;
        			Msg="订单类型不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldOrdertime=(String)request.getParameter("Ordertime");
             
               if(((FieldOrdertime!=null)&(!FieldOrdertime.trim().equals("")))){
            	   FieldOrdertime=FieldOrdertime.trim();
                    goodsorder.setOrdertime(FieldOrdertime);
                  
        		}else
        		{
        			tag=false;
        			Msg="订单日期不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldFname=(String)request.getParameter("Fname");
             
               if(((FieldFname!=null)&(!FieldFname.trim().equals("")))){
            	   FieldFname=FieldFname.trim();
                    goodsorder.setFname(FieldFname);
                  
        		}else
        		{
        			tag=false;
        			Msg="品类不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldCatename=(String)request.getParameter("Catename");
             
               if(((FieldCatename!=null)&(!FieldCatename.trim().equals("")))){
            	   FieldCatename=FieldCatename.trim();
                    goodsorder.setCatename(FieldCatename);
                  
        		}else
        		{
        			tag=false;
        			Msg="品种不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldSpec=(String)request.getParameter("Spec");
             
               if(((FieldSpec!=null)&(!FieldSpec.trim().equals("")))){
            	   FieldSpec=FieldSpec.trim();
                    goodsorder.setSpec(FieldSpec);
                  
        		}else
        		{
        			tag=false;
        			Msg="规格不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldTarget=(String)request.getParameter("Target");
             
               if(((FieldTarget!=null)&(!FieldTarget.trim().equals("")))){
            	   FieldTarget=FieldTarget.trim();
                    goodsorder.setTarget(FieldTarget);
                  
        		}else
        		{
        			tag=false;
        			Msg="对象不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldOrderstatus=(String)request.getParameter("Orderstatus");
             
               if(((FieldOrderstatus!=null)&(!FieldOrderstatus.trim().equals("")))){
            	   FieldOrderstatus=FieldOrderstatus.trim();
                    goodsorder.setOrderstatus(FieldOrderstatus);
                  
        		}else
        		{
        			tag=false;
        			Msg="状态不能为空！";
        		}
        		}
	         
            
            MyJson mj=new MyJson();
              if(tag){
                     goodsorderService.EditSave(goodsorder);	 
        			 mj.setStatusCode(200);
        		 }else
        		 {
        			 mj.setStatusCode(300);
        		 }
             mj.setMessage(Msg);
             mj.setForwardUrl("/MemGoodsorder/Index.do");
             mj.setCallbackType("forward");
             String str=mj.getJson();
			 response.getWriter().print(str);
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
	} 
    
	/*删除*/
	@RequestMapping("Del.do")
	public void Del(HttpSession session,HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
             String ID=request.getParameter("ID");
             goodsorderService.Del(ID);
             String Msg="数据删除成功";
             MyJson mj=new MyJson();
             mj.setStatusCode(200);
             mj.setMessage(Msg);
             mj.setForwardUrl("/MemGoodsorder/Index.do");
             mj.setCallbackType("forward");
             String str=mj.getJson();
             try {
                  response.getWriter().print(str);
                 } catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                 }
	      }
          	/*编辑*/
	@RequestMapping("Detail.do")
	public String Detail(HttpSession session,HttpServletRequest request,ModelMap modelMap)
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		String ID=request.getParameter("ID");
		Goodsorder goodsorder=(Goodsorder)goodsorderService.getGoodsorder(ID);
		modelMap.put("goodsorder", goodsorder);
		return "/MemGoodsorder/Detail";
	}
    
 
}
